{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Examples and Exercises from Think Stats, 2nd Edition\n",
    "\n",
    "http://thinkstats2.com\n",
    "\n",
    "Copyright 2016 Allen B. Downey\n",
    "\n",
    "MIT License: https://opensource.org/licenses/MIT\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from __future__ import print_function, division\n",
    "\n",
    "%matplotlib inline\n",
    "\n",
    "import numpy as np\n",
    "\n",
    "import nsfg\n",
    "import first\n",
    "import thinkstats2\n",
    "import thinkplot"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Examples\n",
    "\n",
    "One more time, I'll load the data from the NSFG."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "live, firsts, others = first.MakeFrames()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "And compute the distribution of birth weight for first babies and others."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Firsts 4413 4363\n",
      "Others 4735 4675\n"
     ]
    }
   ],
   "source": [
    "first_wgt = firsts.totalwgt_lb\n",
    "first_wgt_dropna = first_wgt.dropna()\n",
    "print('Firsts', len(first_wgt), len(first_wgt_dropna))\n",
    " \n",
    "other_wgt = others.totalwgt_lb\n",
    "other_wgt_dropna = other_wgt.dropna()\n",
    "print('Others', len(other_wgt), len(other_wgt_dropna))\n",
    "\n",
    "first_pmf = thinkstats2.Pmf(first_wgt_dropna, label='first')\n",
    "other_pmf = thinkstats2.Pmf(other_wgt_dropna, label='other')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can plot the PMFs on the same scale, but it is hard to see if there is a difference."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      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rKdV1K3BaehTqg8Dv0rZ8i53Pt1RyNvAFSSuBvUrmHwOskbQa+CTZuRSAw8nOtXRi1gOP/mtWI0l/ExHPp5PPvwSm5nmWhKTLgR9FxN2SbgLuiIjFfVRubqm+1oj4ab1rscZWy7FcM8vcIWlvsgf+/GMfPJDon4Aj8pdVmHUOEauF90jMzCwXnyMxM7NcHCRmZpaLg8TMzHJxkJiZWS4OEjMzy8VBYmZmufx/pOoFEALlEIcAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "width = 0.4 / 16\n",
    "\n",
    "# plot PMFs of birth weights for first babies and others\n",
    "thinkplot.PrePlot(2)\n",
    "thinkplot.Hist(first_pmf, align='right', width=width)\n",
    "thinkplot.Hist(other_pmf, align='left', width=width)\n",
    "thinkplot.Config(xlabel='Weight (pounds)', ylabel='PMF')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`PercentileRank` computes the fraction of `scores` less than or equal to `your_score`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def PercentileRank(scores, your_score):\n",
    "    count = 0\n",
    "    for score in scores:\n",
    "        if score <= your_score:\n",
    "            count += 1\n",
    "\n",
    "    percentile_rank = 100.0 * count / len(scores)\n",
    "    return percentile_rank"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If this is the list of scores."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "t = [55, 66, 77, 88, 99]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "And you got the 88, your percentile rank is 80."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "80.0"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "PercentileRank(t, 88)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`Percentile` takes a percentile rank and computes the corresponding percentile. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "def Percentile(scores, percentile_rank):\n",
    "    scores.sort()\n",
    "    for score in scores:\n",
    "        if PercentileRank(scores, score) >= percentile_rank:\n",
    "            return score"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The median is the 50th percentile, which is 77."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "77"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Percentile(t, 50)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here's a more efficient way to compute percentiles."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "def Percentile2(scores, percentile_rank):\n",
    "    scores.sort()\n",
    "    index = percentile_rank * (len(scores)-1) // 100\n",
    "    return scores[index]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's hope we get the same answer."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "77"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Percentile2(t, 50)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The Cumulative Distribution Function (CDF) is almost the same as `PercentileRank`.  The only difference is that the result is 0-1 instead of 0-100."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "def EvalCdf(sample, x):\n",
    "    count = 0.0\n",
    "    for value in sample:\n",
    "        if value <= x:\n",
    "            count += 1\n",
    "\n",
    "    prob = count / len(sample)\n",
    "    return prob"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "t = [1, 2, 2, 3, 5]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can evaluate the CDF for various values:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.0, 0.2, 0.6, 0.8, 0.8, 1.0)"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "EvalCdf(t, 0), EvalCdf(t, 1), EvalCdf(t, 2), EvalCdf(t, 3), EvalCdf(t, 4), EvalCdf(t, 5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here's an example using real data, the distribution of pregnancy length for live births."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEKCAYAAAD9xUlFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAGdVJREFUeJzt3X+UVPWd5vH3I78HiCY0OoZGmhiMMOyg0CoCm1XHuKAGNokZNHpGRw6oE1bdSTKLOzPG1cmJSZjJ+nMTIh40G0GNMRLBwRyFjU4gQwPBCMgJSxB78QjDqsFRhHY++8e9fS2K7q6mu29Xd9XzOqcP99761q3PLct66nt/fK8iAjMzM4Djyl2AmZn1HA4FMzPLOBTMzCzjUDAzs4xDwczMMg4FMzPLOBTMzCzjUDAzs4xDwczMMn3LX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W6/BHg0jbW39q2FvpYJPeQaH6dSelYOe+T9MjqgX8P3Ejr7/mngPEkI3BCEpKvF7zG90mG0WgeEmYn8AlJ9wArgGcL2u4l+W9tvZxDwbrSexFxRuGC9MvmXwsXkfzavKKo3Zkl1l04ps0HQN90HJwLgXMj4l1Ja0h6HACHIyIK25dY/wMkv9r/EHiwRFsB34yI7xdtQ10LdQ6i5WGe23LUtrbQpknScRHxbxFxWMkIon9O8sv/JeB84FSSwfJOpeX3/N8BWyLi3Fbq+CVwvqS/j4iDEfGmpAnAfwS+DPwpcG3adiDw3jFup/VAPqZg3W0dMFXSJwEk/YGk04BXSH6F1qXtZrf89CMcD7yZBsLpJL+IS3mOZLdW881qms/eeZLkVqZnAatKrGMVcG3BfvkRSsa8b1FEvAkcUHLbTEhG+mx2ABjajrqLbQc+UTD/C+Cr6b8vkBzk/3UajK2959uB4ZLOTZf3k/RHBetcDKwEHpfUV1INcFxEPAH8LTCxoO1pJLvIrJdzKFi3ioh9JL/Il0p6ieQL6/SIeA/4C+AfJb1IMsrr2yVW948kPYaXgDvSdZVyE8mv39+Q7Hb5o7SuQyRDMT+W7lZqaxueJdkFtDZdz48p/cU+B1gkaS1Jz6F521aTHFguPNDcHitIRsRt9gJwMrA2It4ADqbL2nrPD5EMPf0tSZuBXwNTirb1H0h2R/2Q5M5ma9JdhEuAWyC7p8UngYZjqN96KI+Saj2GpCER8Y6SfU73Ab+NiO9202sfR/Ll98WI+G0O6x8S6b2VJS0ATo6Im0o8ra31nQw8HBGfKdk4Z+kxnYkR8bflrsU6zz0F60nmpr9Ct5DsGvp+ifZdQtI4YAfwXB6BkLok7Q28THIA+O86s7JI7s/7A+V08dox6gv8fbmLsK7hnoKZmWXcUzAzs4xDwczMMg4FMzPLOBTMzCzjUDAzs4xDwczMMv8fjul0/EMw4I8AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "cdf = thinkstats2.Cdf(live.prglngth, label='prglngth')\n",
    "thinkplot.Cdf(cdf)\n",
    "thinkplot.Config(xlabel='Pregnancy length (weeks)', ylabel='CDF', loc='upper left')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`Cdf` provides `Prob`, which evaluates the CDF; that is, it computes the fraction of values less than or equal to the given value.  For example, 94% of pregnancy lengths are less than or equal to 41."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9406427634455619"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cdf.Prob(41)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "`Value` evaluates the inverse CDF; given a fraction, it computes the corresponding value.  For example, the median is the value that corresponds to 0.5."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "39"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cdf.Value(0.5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In general, CDFs are a good way to visualize distributions.  They are not as noisy as PMFs, and if you plot several CDFs on the same axes, any differences between them are apparent."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEKCAYAAAD9xUlFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAIABJREFUeJzt3X2UXXV97/H3Z+ZkMiQikGQqIZOYlPIUQglhCmiq0CqWiCYV9f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cl+1QgaZakys1jvgu8MZkSW41jAAABSUlEQVRbeAnFSeTRPEuxOVs1m4E/qjj25uT9D6e4IdDjFMs/5ydxHQnMSY73AguT82dTLH2N5gH2bPF5fumgpJdS3Afj/1LswrsoOS7g0ORzmQ3LScEayY8o3nW0ruLYM6VJ3mSHsy8DayX9iGK30sqL+VcptjreBPwLxbmJZ0b53P8BvKHaRDPFi/0JyYW35HHgOxR3C3tXRLxA8e6k9iSu24DlyVaJDwA/Sb6Wj7P3/EQ1l1Dc1/tB4KDU8dOAhyRtBN5Ice4B4ESKcxODmI3AXVKtJUl6UUQ8l0y8/ieweDy98CVdA/xHRNwj6Wbgzoi4o0bhjlsS36qIuDfvWKy+jaVeataM7pR0MMWNR/6xBpujfBQ4efxhZWaTE4KNhUcKZmZW5jkFMzMrc1IwM7MyJwUzMytzUjAzszInBTMzK3NSMDOzsv8PLMIN1j3eQh8AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "first_cdf = thinkstats2.Cdf(firsts.totalwgt_lb, label='first')\n",
    "other_cdf = thinkstats2.Cdf(others.totalwgt_lb, label='other')\n",
    "\n",
    "thinkplot.PrePlot(2)\n",
    "thinkplot.Cdfs([first_cdf, other_cdf])\n",
    "thinkplot.Config(xlabel='Weight (pounds)', ylabel='CDF')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this example, we can see that first babies are slightly, but consistently, lighter than others.\n",
    "\n",
    "We can use the CDF of birth weight to compute percentile-based statistics."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "weights = live.totalwgt_lb\n",
    "live_cdf = thinkstats2.Cdf(weights, label='live')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Again, the median is the 50th percentile."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7.375"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "median = live_cdf.Percentile(50)\n",
    "median"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The interquartile range is the interval from the 25th to 75th percentile."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(6.5, 8.125)"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "iqr = (live_cdf.Percentile(25), live_cdf.Percentile(75))\n",
    "iqr"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can use the CDF to look up the percentile rank of a particular value.  For example, my second daughter was 10.2 pounds at birth, which is near the 99th percentile."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "98.82717415357381"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "live_cdf.PercentileRank(10.2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If we draw a random sample from the observed weights and map each weigh to its percentile rank."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "sample = np.random.choice(weights, 100, replace=True)\n",
    "ranks = [live_cdf.PercentileRank(x) for x in sample]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The resulting list of ranks should be approximately uniform from 0-1."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEKCAYAAAD9xUlFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RV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dqXMVSAHy1+b6XrdZ4wJeAfwx8IMnfHfN7JMCegjqmqg4k+WXgE0keA3wXeC29X5SD7R5KcgHwG0mOoTef8AJ6O5BuBz7X9DoOMfpjHncD1ye5f6V5har6RDPf8ZlmWOubwMWs8tkHVfWNJP+J3u63X6S3FfxYquruJC8HPprkH1bV/xn3ezXf3CVVktTn8JEkqc9QkCT1GQqSpD5DQZLUZyhIkvoMBUlSn6EgSeozFCRJff8fl6o6r1HJnasAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "rank_cdf = thinkstats2.Cdf(ranks)\n",
    "thinkplot.Cdf(rank_cdf)\n",
    "thinkplot.Config(xlabel='Percentile rank', ylabel='CDF')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "That observation is the basis of `Cdf.Sample`, which generates a random sample from a Cdf.  Here's an example."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEKCAYAAAD9xUlFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAIABJREFUeJzt3Xt8VeWd7/HPL9xiEcRyUSFC6IgXWkAgw6XWM9ZKQbSkVqmgndI5Wl5qvVdb2h4dFF9zLK16WvVoOZaqLRXwNqGKg63Rac9U1KAkKOoMVdDIVQ7QokKA/M4fa+3Nzs7OBbJX1r58369XXq619sreP2Kyv/t5nrWex9wdERERgJK4CxARkdyhUBARkSSFgoiIJCkUREQkSaEgIiJJCgUREUlSKIiISJJCQUREkhQKIiKS1DXuAg5Vv379vLy8PO4yRETyyqpVqz509/5tnZd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xVSiFIXEW0YdNO6rfsAJoGgsJA2kOhkCW7d+8GgkWAXn/94MwexxxzDPv3729y7hFHHJHsShLJhhV1m7l7+dqMl5OWmHHe2IEKA2kXhYJInksEQtA6aGrowKO5bPJwJo88NobKJB8pFETy2LxFK3ly1cYmrYO+jbs5pvt+XUEkh0WhIJKHWrqqqG/jbq6uPFVhIIdNoSCSZ6qqa3mypp7GtJliju3yCZd/RYEgHaNQEMkj8xatbBYIuqpIskmhIJInMrUQhg48midvPDPGqqTQRLnIjsRs7ty5yak0JP/dt3xNs0C4bPLwGCuSQqSWQgTcHXenpESZK9mz9UBpclstBImK3rWyZP369ZxyyilcccUVjBkzhl//+tdMnDiRMWPGMH369OTNbXPmzGH48OGMHDmSG264AYDf/e53jB8/ntGjR3PWWWexZcsWIPikP2vWLL785S9TXl7OE088wfe+9z1GjBjBlClT2LcvWIWqvLyc73//+4wbN45x48axbt26ZvX95S9/YcqUKYwdO5bTTz+dt956q5N+MtJRVdW1XHTjL5u0EtRCkKgUXEvh0geiW6XpgUsrWn387bff5le/+hW33norX/va1/jDH/5Az549+fGPf8ydd97JlVdeyZNPPslbb72FmbFz504AvvCFL7By5UrMjAceeID58+dzxx13AMGb+fPPP8/atWuZOHEijz/+OPPnz+e8887j6aef5qtf/SoAvXv35uWXX+bhhx/m2muvbTZtxuzZs7n//vsZNmwYL730EldccQXV1dUR/JQkm6qqa/l51Wp2lByVPFZippvRJDIFFwpxGjJkCBMmTOCpp55i7dq1nHbaaQA0NDQwceJEevfuTWlpKZdeeinnnHMO5557LgD19fVceOGFbNq0iYaGBoYOHZp8zrPPPptu3boxYsQIDhw4wJQpUwAYMWIE69evT543c+bM5H+vu+66JnXt3r2bP//5z8mpuwH27t0byc9Asuu+5WvYXnJkcr/EjCHH9YmxIil0CoUsSiyS4+5MmjSJRx55pNk5L7/8Ms899xyLFy/mnnvuobq6mquuuorrr7+eadOm8cILLzB37tzk+T169ACgpKSEbt26YWbJ/dQ5lRLH07cBGhsb6dOnD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8AeCVaq6EHwaLwF2uvuprbxGW9MNt6eGdPvNrMTdE2tVpM8342287n4Odv+mL/XZUj0tzWlzDkHYTANuMrPPhmFaCnzSSg1SgNRSkNiFffhdCLo6WvM3ggnSDtUfgWuBF919G9AXOBl4I/zU/K6ZTQ9rMTMblfrN7r4D+JuZTQgPtXdpzX0WTI+eydsECwUlDLaDa0zPBP4vQddauZmdEB7/R+Dfw+31BF1CAOe3o5Y/AueZ2RFm1gv4CoCZlRB0dz1PsKBSH+DI8HtOJOg2kyKiUJC4JAZhVwNLCGZwPNDG99QRfMKuTRlobo+XCLpQ/pjyPHXunvjkfDFwiZnVAm+QednWS4AFZvYiwSf4Xe143QVAXQsDzU8TjJEkvAnMsmDG108TLB60B/gngq6tNQTz4SdmCr0F+JmZ/YmgNdAqD5Z+XUIwjvM4QesJgjD+Tfj8rwF3+cFlTb8Y1ilFRLOkirSDmR3p7rvD7TnAce5+TQee7zjgYXefZMFyrE+5++eyUmwWmNkxwG/d/Utx1yKdS2MKIu1zjpn9gOBvZgPBVUeHzd03mdn/ievmtXYYDHw37iKk86mlICIiSRpTEBGRJIWCiIgkKRRERCRJoSAiIkkKBRERSVIoiIhI0v8HZyl1hRN7TGEAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "resample = live_cdf.Sample(1000)\n",
    "thinkplot.Cdf(live_cdf)\n",
    "thinkplot.Cdf(thinkstats2.Cdf(resample, label='resample'))\n",
    "thinkplot.Config(xlabel='Birth weight (pounds)', ylabel='CDF')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This confirms that the random sample has the same distribution as the original data."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Exercises"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "**Exercise:** How much did you weigh at birth? If you don’t know, call your mother or someone else who knows. Using the NSFG data (all live births), compute the distribution of birth weights and use it to find your percentile rank. If you were a first baby, find your percentile rank in the distribution for first babies. Otherwise use the distribution for others. If you are in the 90th percentile or higher, call your mother back and apologize."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "**Exercise:** The numbers generated by `numpy.random.random` are supposed to be uniform between 0 and 1; that is, every value in the range should have the same probability.\n",
    "\n",
    "Generate 1000 numbers from `numpy.random.random` and plot their PMF.  What goes wrong?\n",
    "\n",
    "Now plot the CDF. Is the distribution uniform?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
